﻿
$(document).ready(function () {
    // $("input#txtTAAmount").numeric();
    $("#transport-a-modal span#vldTAAmount").hide();

    $("#transport-a-modal input#btnTAOK").click(function () {
        if (!validateAmount_60pt($("#transport-a-modal input#txtTAAmount"))) {
            $("#transport-a-modal span#vldTAAmount").show();
            return;
        }
        else {
            $("#transport-a-modal span#vldTAAmount").hide();
        }

        processTA();
        $.fancybox.close();
    });

    $("#transport-a-modal input#btnTACancel").click(function () {
        $.fancybox.close();
    });

    $("#transport-a-modal select#ddlTAFlows").on('change', function () {
        var val = $(this).val();

        var select = $("select#ddlTAUnit", $(this).closest("#transport-a-modal"));
        filterUnitDropdown("Flow", val, select);
    });
});

function resetTAModal() {
    $("#transport-a-modal select#ddlTAFlows option:eq(0)").prop('selected', 'selected');
    $("#transport-a-modal input#txtTAAmount").val('');
    $("#transport-a-modal select#ddlTAFlows").trigger("change");
}

function loadTAModal(selectedRow) {
    $("#transport-a-modal select#ddlTAFlows").val(selectedRow.item_id);
    $("#transport-a-modal input#txtTAAmount").val(selectedRow.amount);
    $("#transport-a-modal select#ddlTAFlows").trigger("change");
    $("#transport-a-modal select#ddlTAUnit").val(selectedRow.unit_id);
}

function processTA() {
    var item_id = $("#transport-a-modal select#ddlTAFlows").val();
    var item_name = $.trim($("#transport-a-modal select#ddlTAFlows option:selected").text().split('-')[1]);


    var amount = $("#transport-a-modal input#txtTAAmount").val();
    var unit_id = $("#transport-a-modal select#ddlTAUnit").val();
    var unit_name = $("#transport-a-modal select#ddlTAUnit option:selected").text();
    unit_name = $.trim(unit_name.split('-')[1]);

    var row = {
        item_id: item_id,
        item_type: 'Flow',
        item_name: item_name,
        amount: amount,
        unit_id: unit_id,
        unit_name: unit_name
    };

    callbackFromTAModal(row);
}
